package com.esri.android.map.popup;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISPopupInfo;
import com.esri.android.map.popup.ArcGISPopupStyle;
import com.esri.core.geometry.Geometry;
import com.esri.core.internal.util.b;
import com.esri.core.map.EditFieldsInfo;
import com.esri.core.map.EditInfo;
import com.esri.core.symbol.Symbol;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.EnumSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.achartengine.internal.chart.j;

/* loaded from: classes.dex */
public class ArcGISTitleView extends RelativeLayout implements ArcGISPopupStyle.IPopupStylable, PopupRefreshable {
    private static final String A = " ${hours} hours ago";
    private static final String B = " on ${weekday} at ${formattedTime}";
    private static final String C = " on ${formattedDate} at ${formattedTime}";
    static final int a = 48;
    private static final int e = 1;
    private static final int f = 1;
    private static final int g = 2;
    private static final int h = 2;
    private static final int i = 0;
    private static final int j = 1;
    private static final int k = 2;
    private static final int l = 3;
    private static final int m = 4;
    private static final int n = 5;
    private static final int o = 60000;
    private static final int p = 3600000;
    private static final int q = 86400000;
    private static final int r = 604800000;
    private static final String s = "Created";
    private static final String t = "Edited";
    private static final String u = "Created by ${userId}";
    private static final String v = "Edited by ${userId}";
    private static final String w = " seconds ago";
    private static final String x = " a minute ago";
    private static final String y = " ${minutes} minutes ago";
    private static final String z = " an hour ago";
    private int D;
    private int E;
    private int F;
    private int G;
    private boolean H;
    Popup b;
    MapView c;
    ArcGISValueFormat d;
    protected TextView mEditInfo;
    protected TextView mGeometryInfo;
    protected Symbol mSymbol;
    protected ImageView mSymbolView;
    protected TextView mTitle;

    public ArcGISTitleView(Context context, Popup popup, MapView mapView) {
        super(context);
        this.D = 1;
        this.E = 1;
        this.F = 2;
        this.G = 2;
        this.b = popup;
        this.c = mapView;
        this.mSymbol = popup.b.getSymbol();
        this.d = new ArcGISValueFormat(popup);
        ArcGISPopupStyle arcGISPopupStyle = (ArcGISPopupStyle) this.b.getLayout().getStyle();
        arcGISPopupStyle.registerStylable(this);
        TextView textView = new TextView(getContext());
        this.mTitle = textView;
        textView.setId(1);
        this.mTitle.setPadding(10, 0, 0, 0);
        this.mTitle.setTextSize(1, arcGISPopupStyle.getPopupTitleFontSize());
        this.mTitle.setTypeface(arcGISPopupStyle.getPopupTitleFontType(), arcGISPopupStyle.getPopupTitleFontStyle());
        this.mTitle.setTextColor(arcGISPopupStyle.getPopupTitleColor());
        TextView textView2 = new TextView(getContext());
        this.mGeometryInfo = textView2;
        textView2.setId(2);
        this.mGeometryInfo.setPadding(10, 0, 0, 0);
        TextView textView3 = new TextView(getContext());
        this.mEditInfo = textView3;
        textView3.setId(3);
        this.mEditInfo.setPadding(10, 0, 0, 0);
        ImageView imageView = new ImageView(getContext());
        this.mSymbolView = imageView;
        imageView.setPadding(this.D, this.E, this.F, this.G);
        this.mSymbolView.setId(4);
        this.mSymbolView.setFocusable(true);
        this.mSymbolView.setFocusableInTouchMode(true);
        this.mSymbolView.setScaleType(ImageView.ScaleType.CENTER);
        int convertDpInPixels = PopupUtil.convertDpInPixels(getContext(), 48);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(convertDpInPixels, convertDpInPixels);
        layoutParams.addRule(9, -1);
        addView(this.mSymbolView, layoutParams);
        RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams2.addRule(1, this.mSymbolView.getId());
        addView(this.mTitle, layoutParams2);
        RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams3.addRule(1, this.mSymbolView.getId());
        layoutParams3.addRule(3, this.mTitle.getId());
        addView(this.mEditInfo, layoutParams3);
        RelativeLayout.LayoutParams layoutParams4 = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams4.addRule(1, this.mSymbolView.getId());
        layoutParams4.addRule(3, this.mEditInfo.getId());
        addView(this.mGeometryInfo, layoutParams4);
        refresh();
    }

    /* JADX WARN: Removed duplicated region for block: B:68:0x014e  */
    /* JADX WARN: Removed duplicated region for block: B:72:? A[RETURN, SYNTHETIC] */
    @Override // com.esri.android.map.popup.PopupRefreshable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void refresh() {
        /*
            Method dump skipped, instructions count: 338
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.popup.ArcGISTitleView.refresh():void");
    }

    private String a() {
        ArcGISPopupInfo arcGISPopupInfo;
        String str;
        String str2;
        String str3;
        String str4;
        String str5;
        Object attributeValue;
        String a2;
        if ((this.b.a instanceof ArcGISPopupInfo) && (arcGISPopupInfo = (ArcGISPopupInfo) this.b.a) != null) {
            EditFieldsInfo editFieldsInfo = arcGISPopupInfo.getEditFieldsInfo();
            Calendar calendar = null;
            if (editFieldsInfo == null) {
                return null;
            }
            String[] strArr = {"userId", "minutes", "hours", "weekday", "formattedDate", "formattedTime"};
            if (AnonymousClass1.b[(((editFieldsInfo.getEditorField() == null ? null : (String) this.b.b.getAttributeValue(editFieldsInfo.getEditorField())) == null && (editFieldsInfo.getEditDateField() == null ? null : this.b.b.getAttributeValue(editFieldsInfo.getEditDateField())) == null) ? EditInfo.ACTION_TYPE.CREATION : EditInfo.ACTION_TYPE.EDIT).ordinal()] == 1) {
                str = (String) this.b.b.getAttributeValue(editFieldsInfo.getEditorField());
                if (str == null || str.length() == 0) {
                    str2 = t;
                    str3 = "ags_edit";
                } else {
                    str2 = v;
                    str3 = "ags_edit_user";
                }
                String str6 = str3;
                str4 = str2;
                str5 = str6;
                attributeValue = this.b.b.getAttributeValue(editFieldsInfo.getEditDateField());
            } else {
                str = (String) this.b.b.getAttributeValue(editFieldsInfo.getCreatorField());
                if (str == null || str.length() == 0) {
                    str4 = s;
                    str5 = "ags_creation";
                } else {
                    str5 = "ags_creation_user";
                    str4 = u;
                }
                attributeValue = this.b.b.getAttributeValue(editFieldsInfo.getCreationDateField());
            }
            if (attributeValue == null || String.valueOf(attributeValue).length() == 0) {
                if (str == null || str.length() == 0) {
                    return null;
                }
                a2 = a(str5, str4);
            } else {
                long a3 = b.a(attributeValue);
                long currentTimeMillis = System.currentTimeMillis();
                calendar = Calendar.getInstance();
                calendar.setTimeInMillis(a3);
                long j2 = currentTimeMillis - a3;
                if (j2 < 60000) {
                    a2 = a(str5 + "_seconds_ago", str4 + w);
                } else if (60000 <= j2 && j2 < 120000) {
                    a2 = a(str5 + "_a_minute_ago", str4 + x);
                } else if (j2 < 3600000) {
                    a2 = a(str5 + "_minutes_ago", str4 + y);
                } else if (3600000 <= j2 && j2 < 7200000) {
                    a2 = a(str5 + "_an_hour_ago", str4 + z);
                } else if (j2 < j.b) {
                    a2 = a(str5 + "_hours_ago", str4 + A);
                } else if (j.b <= j2 && j2 < 604800000) {
                    a2 = a(str5 + "_weekday", str4 + B);
                } else {
                    a2 = a(str5 + "_full", str4 + C);
                }
            }
            int i2 = 0;
            while (i2 < 6) {
                Matcher matcher = Pattern.compile(String.format("\\$\\{%1$s\\}", strArr[i2])).matcher(a2);
                if (matcher.find()) {
                    String a4 = i2 == 0 ? str : a(i2, calendar);
                    if (a4 == null) {
                        a4 = "";
                    }
                    a2 = matcher.replaceAll(a4);
                }
                i2++;
            }
            return a2;
        }
        return "";
    }

    private String a(String str, String str2) {
        Resources resources = getContext().getResources();
        int identifier = resources.getIdentifier(str, "string", getContext().getPackageName());
        return identifier == 0 ? str2 : resources.getString(identifier);
    }

    private long a(Calendar calendar) {
        return System.currentTimeMillis() - calendar.getTimeInMillis();
    }

    private String a(int i2, Calendar calendar) {
        String l2;
        String str = null;
        if (calendar != null) {
            try {
                if (i2 == 1) {
                    l2 = Long.toString(a(calendar) / 60000);
                } else if (i2 == 2) {
                    l2 = Long.toString(a(calendar) / 3600000);
                } else if (i2 == 3) {
                    l2 = new SimpleDateFormat("EEEE", Locale.getDefault()).format(calendar.getTime());
                } else if (i2 == 4) {
                    l2 = DateFormat.getDateInstance(3).format(calendar.getTime());
                } else if (i2 != 5) {
                    return null;
                } else {
                    l2 = DateFormat.getTimeInstance(3).format(calendar.getTime());
                }
                str = l2;
                return str;
            } catch (Exception e2) {
                Log.e("PopupView", "Date = " + calendar.getTime().toLocaleString(), e2);
                return str;
            }
        }
        return null;
    }

    public void setTitle(String str) {
        TextView textView = this.mTitle;
        if (textView != null) {
            textView.setText(str);
        }
    }

    public void setSymbol(Bitmap bitmap) {
        ImageView imageView = this.mSymbolView;
        if (imageView != null) {
            imageView.setImageBitmap(bitmap);
            this.H = true;
        }
    }

    public void setSymbol(Drawable drawable) {
        ImageView imageView = this.mSymbolView;
        if (imageView != null) {
            imageView.setImageDrawable(drawable);
            this.H = true;
        }
    }

    public void setSymbol(int i2) {
        ImageView imageView = this.mSymbolView;
        if (imageView != null) {
            imageView.setImageResource(i2);
            this.H = true;
        }
    }

    public Symbol getSymbol() {
        return this.mSymbol;
    }

    public void setGeometryInfo(String str) {
        TextView textView = this.mGeometryInfo;
        if (textView != null) {
            SpannableString valueOf = SpannableString.valueOf(str);
            valueOf.setSpan(new StyleSpan(2), 0, valueOf.length(), 0);
            this.mGeometryInfo.setText(valueOf);
            this.mGeometryInfo.setVisibility(0);
            return;
        }
        textView.setVisibility(8);
    }

    public void setEditInfo(String str) {
        TextView textView = this.mEditInfo;
        if (textView != null) {
            if (str == null) {
                textView.setVisibility(8);
                return;
            }
            SpannableString valueOf = SpannableString.valueOf(str);
            valueOf.setSpan(new StyleSpan(2), 0, valueOf.length(), 0);
            this.mEditInfo.setText(valueOf);
            this.mEditInfo.setVisibility(0);
        }
    }

    public MapView getMapView() {
        return this.c;
    }

    public void setMapView(MapView mapView) {
        this.c = mapView;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.esri.android.map.popup.ArcGISTitleView$1  reason: invalid class name */
    /* loaded from: classes.dex */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] a;
        static final /* synthetic */ int[] b;
        static final /* synthetic */ int[] c;

        static {
            int[] iArr = new int[ArcGISPopupStyle.STYLE_ELEMENT.values().length];
            c = iArr;
            try {
                iArr[ArcGISPopupStyle.STYLE_ELEMENT.POPUP_TITLE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                c[ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            int[] iArr2 = new int[EditInfo.ACTION_TYPE.values().length];
            b = iArr2;
            try {
                iArr2[EditInfo.ACTION_TYPE.EDIT.ordinal()] = 1;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                b[EditInfo.ACTION_TYPE.CREATION.ordinal()] = 2;
            } catch (NoSuchFieldError unused4) {
            }
            int[] iArr3 = new int[Geometry.Type.values().length];
            a = iArr3;
            try {
                iArr3[Geometry.Type.ENVELOPE.ordinal()] = 1;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                a[Geometry.Type.MULTIPOINT.ordinal()] = 2;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                a[Geometry.Type.POLYGON.ordinal()] = 3;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                a[Geometry.Type.LINE.ordinal()] = 4;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                a[Geometry.Type.POLYLINE.ordinal()] = 5;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                a[Geometry.Type.POINT.ordinal()] = 6;
            } catch (NoSuchFieldError unused10) {
            }
        }
    }

    @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
    public void applyStyle(ArcGISPopupStyle arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT style_element) {
        int i2 = AnonymousClass1.c[style_element.ordinal()];
        if (i2 != 1) {
            if (i2 != 2) {
                return;
            }
            setBackgroundColor(arcGISPopupStyle.getPopupBackgroundColor());
            return;
        }
        this.mTitle.setTextSize(1, arcGISPopupStyle.getPopupTitleFontSize());
        this.mTitle.setTypeface(arcGISPopupStyle.getPopupTitleFontType(), arcGISPopupStyle.getPopupTitleFontStyle());
        this.mTitle.setTextColor(arcGISPopupStyle.getPopupTitleColor());
    }

    @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
    public Set<ArcGISPopupStyle.STYLE_ELEMENT> getRegisteredStyle() {
        return EnumSet.of(ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND, ArcGISPopupStyle.STYLE_ELEMENT.POPUP_TITLE);
    }
}
